package com.example.xx.service;

import com.example.xx.dao.UserDao;
import com.example.xx.pojo.TPermission;
import com.example.xx.pojo.TRole;
import com.example.xx.pojo.User;
import com.example.xx.util.MD5Uitl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements com.example.xx.service.UserService {

   @Autowired
   private UserDao userDao;
    @Override
    public int zhuce(User user) {// 注册
        // 页面传递过来的密码是明文  但是数据库要加密的 所以此时要把页面传递过来的密码进行加
        String miwen = MD5Uitl.encrypt(user.getPassword());
        System.out.println(miwen);
        // 把user中的密码改成密文
        user.setPassword(miwen);
        User login = userDao.login(user);
        if (login != null) {
            return 1;
        } else {
            return userDao.zhuce(user);// 返回受影响的行数
        }

    }

    @Override
    public User login(User user) {// 登录
        return userDao.login(user);

    }

    @Override
    public User cha(Integer id) {
        return  userDao.cha(id);
    }

    @Override
    public int xiugai(User user) {
        return  userDao.xiugai(user);
    }

    @Override
    public int shangchaun(User user) {
        return userDao.shangchaun(user);
    }
    // 修改密码


    @Override
    public int xiugaimima(User user) {
        String miwen = MD5Uitl.encrypt(user.getPassword());
        user.setPassword(miwen);
        return userDao.xiugaimima(user);
    }

    @Override
    public List<TRole> getRole(Integer id) {
        return userDao.getRole(id);
    }

    @Override
    public List<TPermission> getPermission(Integer id) {
        return userDao.getPermission(id);
    }

}
